<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>用户管理</title>
    <link href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link href="../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link href="../static/css/login.min.css" th:href="@{/css/login.min.css}" rel="stylesheet"/>
    <!-- 360浏览器急速模式 -->
    <meta name="renderer" content="webkit">
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="shortcut icon" href="../static/favicon.ico" th:href="@{favicon.ico}"/>
    <style type="text/css">
        label.error { position:inherit;  }
        .signinpanel {
            color: #1a2226;
        }
    </style>
    <script>
        if(window.top!==window.self){alert('未登录或登录超时。请重新登录');window.top.location=window.location};
    </script>
</head>
<body class="signin">
    <div class="signinpanel">
        <div class="row">

            <div class="col-sm-6">
                <form id="signupForm" autocomplete="off">
                    <h4 class="no-margins">创建 或 删除用户：</h4>
                    <p class="m-t-md"></p>
                    <input type="text" name="newUserName" class="form-control uname"  placeholder="用户名（姓名拼音全拼）" value="" required/>
<!--                    <input type="text" name="dept" class="form-control uname"  placeholder="所属部门，如：dept_growing" value="" />-->
                    <select name="dept" id="dept" class="form-control uname" required>
                        <option value="">---请选择该用户所属部门---</option>
                        <option value="dept_hr">人力行政中心</option>
                        <option value="dept_growing">产业发展中心</option>
                        <option value="dept_finance">财务中心</option>
                        <option value="dept_dev">研发中心</option>
                        <option value="dept_operation">产业运营中心</option>
                        <option value="personal">首席战略官</option>
                        <option value="area_yangtze">长三角区域中心</option>
                        <option value="area_southwest">西南区域中心</option>
                    </select>
                    <h5 class="no-margins">用户的默认密码请查阅维护文档（用户名+1234）。</h5>

                    <p>&nbsp;</p>
                    <h4 class="no-margins">验证你的身份：</h4>
                    <p class="m-t-md"></p>
                    <input type="text"     name="username" class="form-control uname"  placeholder="你的用户名" value="" />
                    <input type="password" name="password" class="form-control pword"  placeholder="你的密码" value="" />
                    <input type="hidden" name="seCode4user" th:value="${seCode4user}" />

                    <div class="col-lg-12">
                        <button class="btn btn-success btn-block" id="btnSubmit" data-loading="正在提交，请稍候...">创建用户</button>
                    </div>
                </form>
                <div class="col-lg-12">
                    <button class="btn btn-warning btn-block" id="btnSubmit2" data-loading="正在提交，请稍候...">删除用户</button>
                </div>
            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                文件管理系统 Copyright © 2021-2024  All Rights Reserved. <br>
            </div>
        </div>
    </div>
    <script th:inline="javascript"> var ctx = [[@{/}]]; </script>
<!-- 全局js -->
    <script src="../static/jquery.min.js" th:src="@{/jquery.min.js}"></script>
    <script src="../static/validate/jquery.validate.min.js" th:src="@{/validate/jquery.validate.min.js}"></script>
    <script src="../static/layer/layer.min.js" th:src="@{/layer/layer.min.js}"></script>

    <script>

    $(function() {
        validateRule();

        $("#btnSubmit2").bind("click", function () {
            deleteUser();
        });
    });

    $.validator.setDefaults({
        submitHandler: function() {
            createUser();
        }
    });

    function deleteUser() {
        // $.modal.loading($("#btnSubmit").data("loading"));
        var username = trim($("input[name='username']").val());
        var password = trim($("input[name='password']").val());
        var newUserName = trim($("input[name='newUserName']").val());
        var dept = trim($("#dept").val());
        var seCode4user = trim($("input[name='seCode4user']").val());
        console.log(password);
        $.ajax({
            type: "post",
            url: "/user/doDelete",
            data: {
                "uname": username,
                "pwd": password,
                "newUserName": newUserName,
                "dept": dept,
                "seCode": seCode4user
            },
            success: function(r) {
                if (r == web_status.SUCCESS) {
                    // location.href = ctx + 'index';
                    $(".form-control").val("");
                    alert("删除成功！");
                } else {
                    alert(r);
                }
            }
        });
        // 空格截取
        function trim(value) {
            if (value == null) {
                return "";
            }
            return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
        }
    }

    function createUser() {
        // $.modal.loading($("#btnSubmit").data("loading"));
        var username = trim($("input[name='username']").val());
        var password = trim($("input[name='password']").val());
        var newUserName = trim($("input[name='newUserName']").val());
        var dept = trim($("#dept").val());
        var seCode4user = trim($("input[name='seCode4user']").val());
        $.ajax({
            type: "post",
            url: "/user/doCreate",
            data: {
                "uname": username,
                "pwd": password,
                "newUserName": newUserName,
                "dept": dept,
                "seCode": seCode4user
            },
            success: function(r) {
                if (r == web_status.SUCCESS) {
                    // location.href = ctx + 'index';
                    $(".form-control").val("");
                    alert("创建成功！请使用FTP登录。");
                } else {
                    alert(r);
                }
            }
        });
        // 空格截取
        function trim(value) {
            if (value == null) {
                return "";
            }
            return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                username: {
                    required: true
                },
                password: {
                    required: true
                },
                newUserName: {
                    required: true
                },
                dept: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: icon + "请输入您的用户名",
                },
                password: {
                    required: icon + "请输入您的密码",
                },
                newUserName: {
                    required: icon + "请输入您要创建用户的用户名",
                },
                dept: {
                    required: icon + "请输入您要创建用户的部门",
                }
            }
        })
    }

    /** 消息状态码 */
    web_status = {
        SUCCESS: 0,
        FAIL: 500,
        WARNING: 301
    };
</script>
</body>
</html>
